package com.atguigu.eduservice.mapper;

import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.frontvo.CourseWebVo;
import com.atguigu.eduservice.entity.vo.CoursePublishVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 课程 Mapper 接口
 * </p>
 *
 * @author testjava
 * @since 2020-03-02
 */
public interface EduCourseMapper extends BaseMapper<EduCourse> {

    @Select("SELECT ec.id,ec.title,ec.price,ec.lesson_num AS lessonNum,ec.cover,\n" +
            "               et.name AS teacherName,\n" +
            "               es1.title AS subjectLevelOne,\n" +
            "               es2.title AS subjectLevelTwo\n" +
            "        FROM edu_course ec LEFT OUTER JOIN edu_course_description ecd ON ec.id=ecd.id\n" +
            "                           LEFT OUTER JOIN edu_teacher et ON ec.teacher_id=et.id\n" +
            "                           LEFT OUTER JOIN edu_subject es1 ON ec.subject_parent_id=es1.id\n" +
            "                   LEFT OUTER JOIN edu_subject es2 ON ec.subject_id=es2.id\n" +
            "        WHERE ec.id=#{courseId}")
    public CoursePublishVo getPublishCourseInfo(@Param("courseId") String courseId);

    @Select("SELECT ec.id,ec.title,ec.price,ec.lesson_num AS lessonNum,ec.cover,\n" +
            "               ec.buy_count AS buyCount,ec.view_count AS viewCount,\n" +
            "               ecd.description, et.id AS teacherId, et.name AS teacherName,\n" +
            "               et.intro ,et.avatar,\n" +
            "               et.name AS teacherName,\n" +
            "               es1.id AS subjectLevelOneId,\n" +
            "               es1.title AS subjectLevelOne,\n" +
            "               es2.id AS subjectLevelTwoId,\n" +
            "               es2.title AS subjectLevelTwo\n" +
            "        FROM edu_course ec LEFT OUTER JOIN edu_course_description ecd ON ec.id=ecd.id\n" +
            "                           LEFT OUTER JOIN edu_teacher et ON ec.teacher_id=et.id\n" +
            "                           LEFT OUTER JOIN edu_subject es1 ON ec.subject_parent_id=es1.id\n" +
            "                   LEFT OUTER JOIN edu_subject es2 ON ec.subject_id=es2.id\n" +
            "        WHERE ec.id= #{course}")
    CourseWebVo getBaseCourseInfo(@Param("course") String courseId);

    @Select("SELECT ec.id,ec.title,ec.price,ec.lesson_num AS lessonNum,ec.cover,\n" +
            "               ec.buy_count AS buyCount,ec.view_count AS viewCount,\n" +
            "               ecd.description, et.id AS teacherId, et.name AS teacherName,\n" +
            "               et.intro ,et.avatar,\n" +
            "               et.name AS teacherName,\n" +
            "               es1.id AS subjectLevelOneId,\n" +
            "               es1.title AS subjectLevelOne,\n" +
            "               es2.id AS subjectLevelTwoId,\n" +
            "               es2.title AS subjectLevelTwo\n" +
            "        FROM edu_course ec LEFT OUTER JOIN edu_course_description ecd ON ec.id=ecd.id\n" +
            "                           LEFT OUTER JOIN edu_teacher et ON ec.teacher_id=et.id\n" +
            "                           LEFT OUTER JOIN edu_subject es1 ON ec.subject_parent_id=es1.id\n" +
            "                   LEFT OUTER JOIN edu_subject es2 ON ec.subject_id=es2.id\n" +
            "        WHERE ec.id= #{course}")
    public CourseWebVo test01( @Param("course") String course);
}
